﻿namespace ChessToys
{
    using System;
    using System.Collections.Generic;

    /// <summary>
    /// Abstract extension of <see cref="AbstractMoveGenerator"/> providing functionality to verfy the deriving move
    /// generator supports the piece at the start position.
    /// </summary>
    /// <typeparam name="TPiece">The type of the piece.</typeparam>
    public abstract class AbstractPieceMoveGenerator<TPiece> : AbstractMoveGenerator where TPiece : IPiece
    {
        /// <inheritdoc />
        protected override ISet<Move> GenerateForPiece(Board board, Position start, IPiece piece)
        {
            // check if piece type is supported
            if (piece.GetType() != typeof(TPiece))
            {
                throw new ArgumentException(String.Format("Unable to move {0}", piece.GetType()));
            }
            // generate piece specific moves
            return GenerateForSpecificPiece(board, start, (TPiece)piece);
        }

        /// <summary>
        /// Generates all possible moves for specific piece.
        /// </summary>
        /// <param name="board">The board.</param>
        /// <param name="start">The start.</param>
        /// <param name="piece">The piece.</param>
        /// <returns>All possible moves for specific piece.</returns>
        protected abstract ISet<Move> GenerateForSpecificPiece(Board board, Position start, TPiece piece);
    }
}
